package com.zhike.b2b.info.impl;

import org.springframework.stereotype.Service;

import com.zhike.b2b.base.BaseService;
import com.zhike.b2b.info.IInfoService;

@Service
public class InfoService  extends BaseService implements IInfoService {

	/**
	 * 获取未读信息 
	 * @param userId
	 * @return
	 */
	public int getMessNum(String userId)
	{
	    int i = 0;
	    String sql = "select count(paylist_id) from infolist where rece_user= ? and ifread = 0";
	    i = jt.queryForInt(sql, userId);
	    return i;
	 }
	
	  public int getMessNum(String entityName, String type)
	  {
		String idClmn = entityName;
		if(entityName.equals("company"))
		   idClmn = "CUST_ID";
		else
	      idClmn += "_id";
	    String criClmm = "";
	    if (entityName.equals("company"))
	      criClmm = "cust_state";
	    else if (entityName.equals("news"))
	      criClmm = "info_state";
	    else
	      criClmm = "validity";
	    String sql = "";
	    if (type.equals("all"))
	    {
	      if (entityName.equals("company"))
	        sql = "select count(" + idClmn + ") from " + entityName + " where cust_state !='9' and cust_type!='0'";
	      if (entityName.equals("news"))
	        sql = "select count(" + idClmn + ") from " + entityName + " where info_state = '1' or info_state='7' or info_state='8'";
	    }else{
	        sql = "select count(" + idClmn + ") from " + entityName + " where " + criClmm + "='" + type + "'";
	    }
	    return jt.queryForInt(sql);
	  }
	  
}
